package com.he.hsdyc.config.mvc;//package com.szdtoo.config.mvc;
//
//import org.apache.http.HttpStatus;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@Component
//public class CorsFilter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest)servletRequest;
//        HttpServletResponse response = (HttpServletResponse)servletResponse;
//        response.setHeader("Access-Control-Allow-Origin","*");
//        if("OPTIONS".equalsIgnoreCase(request.getMethod())) {
//            response.setStatus(HttpStatus.SC_NO_CONTENT);
//            response.setHeader("Access-Control-Allow-Methods", "POST, GET, DELETE, OPTIONS, DELETE, PUT，PATCH");//当判定为预检请求后，设定允许请求的方法
//            response.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, x-requested-with, Accept ,token"); //当判定为预检请求后，设定允许请求的头部类型
//            response.addHeader("Access-Control-Max-Age", "2592000");
//        }else {
//            response.setHeader("Access-Control-Allow-Headers"," Origin, X-Requested-With, Content-Type, Accept, token");
//            response.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE ,PATCH");
//        }
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
